export default class SIPError extends Error {
  static ErrorCode = {
    mic: 101,
    camera: 102,
    network: 103,
    params: 104,
    unknown: 999,
  };
  static ErrorCodeDict = {
    [SIPError.ErrorCode.mic]: '麦克风未授权',
    [SIPError.ErrorCode.camera]: '摄像头未授权',
    [SIPError.ErrorCode.params]: '参数错误',
    [SIPError.ErrorCode.network]: '网络异常',
    [SIPError.ErrorCode.unknown]: '未知错误',
  };

  constructor(code, err) {
    const currentCode = code || 999;
    const typeMessage = SIPError.ErrorCodeDict[currentCode];
    const errorMessage =
      err || `[Error] code: ${currentCode}, message: ${typeMessage || '未知错误'}`;

    super(errorMessage);

    this.name = 'SIPSDKError';
    this.code = currentCode;
  }
}
